
from fastapi import FastAPI
import uvicorn
from nicegui import ui

app = FastAPI()
def fastapi(app:FastAPI):
    @app.get('/')
    def read_root():
        return {'Hello': 'World'}
fastapi(app)

def nicegui(app: FastAPI) -> None:
    @ui.page('/a')
    def a():
        ui.label("this is aaaaaaaaaaaaaaa")
    @ui.page('/b')
    def b():
        import plotly.express as px
        df = px.data.gapminder()
        df2007 = df.query("year == 2007")
        print(df2007.head())
        fig = px.scatter(df2007,
                         x="gdpPercap",
                         y="lifeExp",
                         color="continent",
                         title="A Plotly Express Figure",
                         size='pop',
                         size_max=60
                         )
        ui.plotly(fig)
    ui.run_with(app)
nicegui(app)


def main():
    # 使用uvicorn运行FastAPI应用，指定主机地址和端口
    uvicorn.run(app, host="127.0.0.1", port=8000, log_level="info")

if __name__ == "__main__":
    main()